package com.example.woke;

import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import cn.xl.xxl.imagecache.ImageLoader;

import com.zhongcai.online.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class BorrowsucessActivity extends Activity {
	

	private TextView mTmoney;
//	private String money;
	private ArrayList<String> listsuc;
	private TextView mTorder,mTdtime,mTlili1,mTstime,mTtolal2;
	private TextView mTfor;
	private TextView mTname;
	private ImageView mIcon;
	private ImageLoader imageLoader;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_borrowsucess);
		
		
		imageLoader = new ImageLoader(this);
		Intent intent = getIntent();
		listsuc = intent.getStringArrayListExtra("listsuc");
		intview();
		
	}
	
	@Override
	protected void onDestroy() {
		imageLoader.clearCache();
		imageLoader.clearMemoryCache();
		super.onDestroy();
	}

	private void intview() {
		mTorder = (TextView) findViewById(R.id.avborrows_text_orderno);
		mTdtime = (TextView) findViewById(R.id.avborrows_text_dtime);
		mTlili1 = (TextView) findViewById(R.id.avborrows_text_llili1);
		mTstime = (TextView) findViewById(R.id.avborrows_text_stime);
		mTtolal2 = (TextView) findViewById(R.id.avborrows_text_totalli2);
		mTmoney = (TextView) findViewById(R.id.avborrowinfod_text_totalmoney);
		mTfor = (TextView) findViewById(R.id.avborrowsucess_usefor);
		mTname = (TextView) findViewById(R.id.avborrowsucess_text_name);
		mIcon = (ImageView) findViewById(R.id.avborrowsucess_text_icon);
		//金额、利息、利息总额、创建时间、还款时间、订单id、用途、借款人、头像
		mTmoney.setText("¥"+listsuc.get(0));
		mTlili1.setText(listsuc.get(1));
		mTtolal2.setText(listsuc.get(2));
		mTstime.setText(listsuc.get(3));
		mTdtime.setText(listsuc.get(4));
		mTorder.setText(listsuc.get(5));
		mTfor.setText(listsuc.get(6));
		mTname.setText(listsuc.get(7));
		imageLoader.DisplayImage(listsuc.get(8), mIcon, false, true, true,0);
		View getshootmap = findViewById(R.id.avborrowsucess_ok);
		getshootmap.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				getmap(v);
			}
		});
		
		findViewById(R.id.avborrowsu_image_back).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	private void getmap(View v) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss",Locale.US);
		        String fname = "/sdcard/"+ sdf.format(new Date()) + ".png";
		        View view = v.getRootView();
		        view.setDrawingCacheEnabled(true);
		        view.buildDrawingCache();
		        Bitmap bitmap = view.getDrawingCache();
		        if(bitmap != null){
		          System.out.println("bitmap got!");
		          try{
		            FileOutputStream out = new FileOutputStream(fname);
		            bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
		            Toast.makeText(BorrowsucessActivity.this, "保存成功！", Toast.LENGTH_SHORT).show();
					finish();
		            System.out.println("file" + fname + "outputdone.");
		          }catch(Exception e){
		            e.printStackTrace();
		          }
		        }else{
		          System.out.println("bitmap is NULL!");
		        }
		      }
	
}
